package gridmath;

import preprocessing.WindowingSystem;
import datastructures.UserParameters;

public class MaxCaseCalculator extends CaseMatrixBase {

//	private final int Cases;
//	private final double prevalence;
	private final double[] freqMaxes;
	
	public MaxCaseCalculator(UserParameters userparams, WindowingSystem windowmaker) {
		super(windowmaker, userparams.getMaxorder());
//		Cases = userparams.getNumber_of_cases();
//		prevalence = userparams.getPrevalence();
		freqMaxes = new double[windowmaker.getWindowBoundaries().length];
		for(int i=0; i<windowmaker.getWindowBoundaries().length; i++)
			freqMaxes[i] = windowmaker.getWindowBoundaries()[i][1]; 
		
		specialTypeOfOperation =  MatrixOperations.calculateMaxCases ;
		specialTypeOfOperand = MatrixOperations.calculateFrequency;
	}
	
	//assuming full penetrance at given prevalence
	public double doOperation (double expectedCarrierFreq) {
		//return Math.round(Cases * expectedCarrierFreq / prevalence);
		
		//return maximal possible overlap of the windows
		switch(currentDimension) {
		case 1:
			return freqMaxes[i];
		case 2:
			return Math.min( freqMaxes[i],  freqMaxes[j] );
		case 3:
			return Math.min( Math.min( freqMaxes[i] , freqMaxes[j] ) , freqMaxes[k] );
		default:
			return Math.min( Math.min( Math.min( freqMaxes[i] , freqMaxes[j] ) , freqMaxes[k] ) , freqMaxes[m] ) ;
		}
	}

}
